package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@JsonIgnoreProperties("handler")
public class SceneCommend extends BaseDomain {

    public static final Integer TYPE_SEASON = 1; //每季
    public static final Integer TYPE_MONTH = 2; //每月
    public static final Integer TYPE_ANNUAL = 3; //年度

    private Scene scene; // 景点对象

    private String title; // 推荐的景点的标题

    private String coverUrl; // 推荐的景点的封面

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date schedule; // 推荐的景点的推荐安排时间

    private Integer type = TYPE_SEASON; //默人是当季的推荐景点

    public String getTypeName() {
        String msg = "当季推荐";
        if (type == TYPE_MONTH) {
            msg = "当月推荐";
        } else if (type == TYPE_ANNUAL) {
            msg = "年度推荐";
        }
        return msg;
    }

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        if (coverUrl != null) {
            map.put("coverUrl", coverUrl);
        }
        map.put("type", type);
        if (schedule != null) {
            map.put("schedule", DateUtil.formatDate(schedule));
        }
        if (scene != null) {
            map.put("sceneId", scene.getId());
            map.put("price", scene.getPrice());
        }
        return JSONUtil.toJSONString(map);
    }
}